package com.youkeda.comment.config;

import com.youkeda.comment.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


//标记为配置类
@Configuration
//启动配置属性
@EnableConfigurationProperties(UserProperties.class)
// 如果没有设置 user.code.enabled 则默认配置生效（matchIfMissing = true）  // 如果设置了 user.code.enabled=false 则配置不生效
@ConditionalOnProperty(prefix = "user.code", value = "enabled", matchIfMissing = true)
public class UserConfig {

    @Autowired
    private UserProperties userProperties;

    @Autowired
    private UserService userService;

    @PostConstruct
    public void init() {
        System.out.println("UserConfig init successful.");

        if (userProperties != null) {
            System.out.println("user.code.message600" + userProperties.getMessage600());

            userService.setUserProperties(userProperties);
        }
    }
}
